package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"os"

	"gopkg.in/yaml.v3"
)

func main() {
	file := flag.String("file", "", "from yaml file")
	flag.Parse()

	if *file == "" {
		fmt.Println("usage: myaml2json -file xxx")
		return
	}
	data, err := os.ReadFile(*file)
	if err != nil {
		fmt.Println(err)
		return
	}
	var value any
	if err := yaml.Unmarshal(data, &value); err != nil {
		fmt.Println(err)
		return
	}

	if out, err := json.MarshalIndent(value, "", "  "); err != nil {
		fmt.Println(err)
		return
	} else {
		fmt.Println(string(out))
	}
}
